package com.yaorange.teaching.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yaorange.common.log.annotation.Log;
import com.yaorange.common.log.enums.BusinessType;
import com.yaorange.common.security.annotation.RequiresPermissions;
import com.yaorange.teaching.domain.YaTeacher;
import com.yaorange.teaching.service.IYaTeacherService;
import com.yaorange.common.core.web.controller.BaseController;
import com.yaorange.common.core.web.domain.AjaxResult;
import com.yaorange.common.core.utils.poi.ExcelUtil;
import com.yaorange.common.core.web.page.TableDataInfo;

/**
 * 教师信息Controller
 * 
 * @author ruoyi
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/teacher")
public class YaTeacherController extends BaseController
{
    @Autowired
    private IYaTeacherService yaTeacherService;

    /**
     * 查询教师信息列表
     */
    @RequiresPermissions("teaching:teacher:list")
    @GetMapping("/list")
    public TableDataInfo list(YaTeacher yaTeacher)
    {
        startPage();
        List<YaTeacher> list = yaTeacherService.selectYaTeacherList(yaTeacher);
        return getDataTable(list);
    }

    /**
     * 导出教师信息列表
     */
    @RequiresPermissions("teaching:teacher:export")
    @Log(title = "教师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YaTeacher yaTeacher)
    {
        List<YaTeacher> list = yaTeacherService.selectYaTeacherList(yaTeacher);
        ExcelUtil<YaTeacher> util = new ExcelUtil<YaTeacher>(YaTeacher.class);
        util.exportExcel(response, list, "教师信息数据");
    }

    /**
     * 获取教师信息详细信息
     */
    @RequiresPermissions("teaching:teacher:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yaTeacherService.selectYaTeacherById(id));
    }

    /**
     * 新增教师信息
     */
    @RequiresPermissions("teaching:teacher:add")
    @Log(title = "教师信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YaTeacher yaTeacher)
    {
        return toAjax(yaTeacherService.insertYaTeacher(yaTeacher));
    }

    /**
     * 修改教师信息
     */
    @RequiresPermissions("teaching:teacher:edit")
    @Log(title = "教师信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YaTeacher yaTeacher)
    {
        return toAjax(yaTeacherService.updateYaTeacher(yaTeacher));
    }

    /**
     * 删除教师信息
     */
    @RequiresPermissions("teaching:teacher:remove")
    @Log(title = "教师信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yaTeacherService.deleteYaTeacherByIds(ids));
    }
}
